package com.config
{
	import com.game.map.tile.RpgTile;
	
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	
	public class SceneConfig extends EventDispatcher
	{
		private var _miniMap:BitmapData;
		
		private var _mapname:String;
		
		private var _width:int;
		private var _height:int;
		
		public static var instance:SceneConfig;
		
		public function SceneConfig(mapid:int)
		{
			var obj:Object = GameConfig.instance.getMapObj(mapid);
			RpgTile.init(obj.name);
			_mapname = obj.name;
			_width = obj.width;
			_height = obj.height;
			RpgTile.width = _width;
			RpgTile.height = _height;
			loadMiniMap();
			instance = this;
		}
		
		public function get miniMap():BitmapData
		{
			return _miniMap;
		}

		public function get height():int
		{
			return _height;
		}

		public function get width():int
		{
			return _width;
		}

		private function loadMiniMap():void
		{
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadMiniMapCompletedHandler);
			loader.load(new URLRequest(encodeURI("map/"+_mapname+"/minimap.jpg")));
		}
		
		private function loadMiniMapCompletedHandler(event:Event):void
		{
			_miniMap = event.target.content.bitmapData as BitmapData;
			this.dispatchEvent(new Event(Event.COMPLETE));
		}
		
		private function errorMiniMapHandler(event:Event):void
		{
			throw new Error("加载 map/"+this._mapname+"/minimap.jpg 失败");
		}
	}
}